<template>
  <div class="login">
    <el-card class="box-card">
      <h2><span><img src="../assets/logo.png" alt=""></span></h2>
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item prop="username">
          <el-input
            v-model="ruleForm.username"
            prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="ruleForm.password"
            prefix-icon="el-icon-lock"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm">登陆</el-button>
          <el-button type="info" @click="submtForm">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import axioss from '../http/http'
export default {
  
  data() {
    return {
      ruleForm: {
        username: "",
        password: "",
      },
      rules: {
        username: [{ required: true, message: "请输入账号", trigger: "blur" }],
        password: [{ required: true, message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.ruleForm.validate((valid) => {
        if (valid) {
          axioss.post("login", this.ruleForm).then((res) => {
            if (res.data.meta.status == 200) {
              this.$message({
                message: res.data.meta.msg,
                type: "success",
              });
              sessionStorage.setItem("token", res.data.data.token);
              this.$router.push("/");
            } else {
              this.$message.error(res.data.meta.msg);
            }
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    submtForm() {
      this.ruleForm = {};
    },
  },
};
</script>

<style lang="scss" scoped>
.login {
  color: rgb(212, 22, 22);
  width: 500px;
  height: 400px;
  text-align: center;
  position: absolute;
  top: 50%;
  margin-top: -150px;
  left: 50%;
  margin-left: -250px;
  line-height: 100px;
  border-radius: 100%;
}
h2{
 
 span{
    display: inline-block;
    border: 1px solid #f1f1f1;
    border-radius: 50%;
    width: 130px;
    height: 130px;
  img{
    width: 100px;
    height: 80px;
    margin-top: 30px;
  }
 }
}
</style>
